package com.actions.bluetoothbox2.app;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actions.bluetoothbox2.R;
import com.actions.bluetoothbox2.fragment.MatherSelectionFragment;
import com.actions.bluetoothbox2.fragment.SlideLeftFragment;
import com.actions.bluetoothbox2.util.Utils;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;


public abstract class BaseActivity extends SlidingSherlockFragmentActivity implements ActionBar.OnNavigationListener {
    private static final String TAG = "BaseActivity";
    //    protected SlideoutMenuFragment mSlideoutMenuFragment = null;
    protected SlideLeftFragment mSlideLeftFragment = null;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(null);
        addSlideMenu();
//        actionBarSetup();
    }

    protected void addSlideMenu() {
        SlidingMenu mSlidingMenu = getSlidingMenu();
        mSlidingMenu.setBehindWidth(Utils.getScreenWidth(this));
        // gesture mode
        mSlidingMenu.setTouchModeBehind(SlidingMenu.TOUCHMODE_NONE);

        setBehindContentView(R.layout.fragment_slideoutmenu);
        FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
        mSlideLeftFragment = new SlideLeftFragment();
        fragmentTransaction.replace(R.id.fragment_slideoutmenu, mSlideLeftFragment);
        fragmentTransaction.commit();

		setSlidingActionBarEnabled(false);
    }

    protected void actionBarSetup() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayShowTitleEnabled(true);
        // actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.ab_subtitle);
        // actionBar.setSubtitle(R.string.ab_subtitle);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
//		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
//		}
//		actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
        Drawable myDrawable = getResources().getDrawable(R.drawable.shap_actionbar_bg);
        actionBar.setBackgroundDrawable(myDrawable);
    }

    public boolean onNavigationItemSelected(int itemPosition, long itemId) {

        return true;
    }

    public int getDpAsPxFromResource(int res) {
        return (int) getResources().getDimension(res);
    }

    @Override
    public void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
//        new Handler().post(new Runnable() {
//            public void run() {
//                //初始状态显示左侧菜单
//                getSlidingMenu().showMenu(true);
//            }
//        });
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
    }

    @Override
    public void finish() {
        // TODO Auto-generated method stub
        super.finish();
    }

}
